package traveldreamEJB;

import java.io.Serializable;

import javax.persistence.*;


import digest.ShaDigest;
import supportClass.LoginDTO;


/**
 * The persistent class for the login database table.
 * 
 */
@Entity
@Table(name="login")
@NamedQuery(name="Login.findAll", query="SELECT l FROM Login l")
public class Login implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@Column(name="UTENTE_EMAIL", unique=true, nullable=false, length=45)
	private String utenteEmail;

	@Column(length=255)
	private String psw;

	@Column(nullable=false, length=45)
	private String ruolo;

	//bi-directional one-to-one association to Utente
	@OneToOne
	@JoinColumn(name="UTENTE_EMAIL", nullable=false, insertable=false, updatable=false)
	private Utente utente;

	public Login() {
	}

	public Login(LoginDTO loginDTO) {
		// TODO Auto-generated constructor stub
		this.utenteEmail= loginDTO.getEmail();
		this.psw= ShaDigest.toSHA256Hex( loginDTO.getPsw() );;
		this.ruolo= "USERS";
	}

	public String getUtenteEmail() {
		return this.utenteEmail;
	}

	public void setUtenteEmail(String utenteEmail) {
		this.utenteEmail = utenteEmail;
	}

	public String getPsw() {
		return this.psw;
	}

	public void setPsw(String psw) {
		this.psw = psw;
	}

	public String getRuolo() {
		return this.ruolo;
	}

	public void setRuolo(String ruolo) {
		this.ruolo = ruolo;
	}

	public Utente getUtente() {
		return this.utente;
	}

	public void setUtente(Utente utente) {
		this.utente = utente;
	}

}